package hoang.hut.networkdemo;

import hoang.hut.networkdemo.network.AsyncHttpGet;
import hoang.hut.networkdemo.network.AsyncHttpResponseProcess;
import hoang.hut.networkdemo.network.Utils;
import hoang.hut.networkdemo.network.WebServiceConfig;
import hoang.hut.networkdemo.network.json.ParameterFactory;

import java.util.List;

import org.apache.http.NameValuePair;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

	private Context context;
	
	@TargetApi(Build.VERSION_CODES.GINGERBREAD)
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		int SDK_INT = android.os.Build.VERSION.SDK_INT;
		if (SDK_INT > 8) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		
		context = MainActivity.this;
		
		loadLocationList();
	}
	
	private void loadLocationList(){
		
		List<NameValuePair> params = null;
		params = ParameterFactory.createParamsLocList("90f43e75b0d2ed4b9774792648ce4b87f957b580", WebServiceConfig.ACTION_LOC_LIST, "0", "0");
		
		Utils.log(params.toString());
		
		AsyncHttpGet httpGet = new AsyncHttpGet(
				context, 
				new AsyncHttpResponseProcess(context, true){
					
					@Override
					public void processResponseSuccess(String response) {
						super.processResponseSuccess(response);
						
						Utils.log(response);
					}
					
				},
				params);
		
		httpGet.execute(WebServiceConfig.API_GET_LOCATION_LIST);
	}
	
}
